package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.domain.RestaurantInfo;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.RestaurantInfoServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 餐饮信息：记录餐厅及其食品信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/restaurant/info")
public class RestaurantInfoController
{

    @Autowired
    private RestaurantInfoServiceImpl restaurantInfoService;

    /**
     * 查询餐饮信息：记录餐厅及其食品信息列表
     */

    @GetMapping("/page")
    @ResponseBody
    public R<Page<RestaurantInfo>> getPage(@ParameterObject Page page,@ParameterObject RestaurantInfo restaurantInfo)
    {
        Page<RestaurantInfo> page1 = restaurantInfoService.selectRestaurantInfoList(page, restaurantInfo);
       if(page1==null) return R.failed();
        return R.ok(page1);
    }




    /**
     * 新增保存餐饮信息：记录餐厅及其食品信息
     */

    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody RestaurantInfo restaurantInfo)
    {
        int flag=restaurantInfoService.insertRestaurantInfo(restaurantInfo);
        if(flag==0) return R.failed();
        return R.ok(flag);

    }

    /**
     * 修改餐饮信息：记录餐厅及其食品信息
     */

    @GetMapping("/get/{id}")
    public R<RestaurantInfo> getById(@PathVariable("id") Long id)
    {
        RestaurantInfo restaurantInfo = restaurantInfoService.selectRestaurantInfoById(id);
        if(restaurantInfo==null) return R.failed();
        return  R.ok(restaurantInfo);
    }

    /**
     * 修改保存餐饮信息：记录餐厅及其食品信息
     */


    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody RestaurantInfo restaurantInfo)
    {
        int flag=restaurantInfoService.updateRestaurantInfo(restaurantInfo);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }

    /**
     * 删除餐饮信息：记录餐厅及其食品信息
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {
        int flag=restaurantInfoService.deleteRestaurantInfoById(id);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }
}
